<template>
	<view class="page solid-top bg-white">
		<view class="express-wrap">
			<view class="express-item flex justify-between align-center solid-bottom">
				<view class="text-333 text-lg">快递公司</view>
				<view class="text-333 text-lg" @click="openPicker">
					<text class="text-bf" v-if="!expressCompany.name">请选择快递公司</text>
					<text class="text-333" v-else>{{ expressCompany.name }}</text>
					<text class="cuIcon-right text-bf text-df"></text>
				</view>
			</view>
			<!-- <view class="express-item flex justify-between align-center solid-bottom">
				<view class="text-333 text-lg">发货仓库</view>
				<view class="text-333 text-lg" @click="senderOpenPicker">
					<text class="text-bf" v-if="!senderInfo.name">选择发货仓库</text>
					<text class="text-333" v-else>{{ senderInfo.name }}</text>
					<text class="cuIcon-right text-bf text-df"></text>
				</view>
			</view> -->
			<view class="express-item flex justify-between align-center solid-bottom">
				<view class="text-333 text-lg">快递单号</view>
				<view class="text-333 text-lg flex justify-start align-center">
					<input type="text" v-model="express_no"  class="text-right" placeholder="请输入快递单号" placeholder-class="text-bf" />
					<!-- <text class="cuIcon-scan text-999 text-xl margin-left-sm" @click="handleScan"></text> -->
				</view>
			</view>
		</view>
		<w-picker mode="selector" :defaultProps="defaultProps" ref="selector" @confirm="onConfirm($event)" :options="express_company" themeColor="#FC6497">
		</w-picker>
		<w-picker mode="selector" :defaultProps="defaultProps1" ref="sender" @confirm="senderOnConfirm($event)" :options="sender_list" themeColor="#FC6497">
		</w-picker>
		<view class="express-btn-wrap"><view class="express-btn text-white text-center text-lg" @click="deliverGoods">保存</view></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			expressCompany: {}, //选择的快递公司数据
			express_company: [], //快递公司数据
			sender_list:[],//供应商
			senderInfo:{},//供应商选中数据
			show: false, //picker显示
			// current: 0,//
			defaultProps: { label: 'name', value: 'aid' }, //picker选择
			defaultProps1: { label: 'name', value: 'id' }, //picker选择
			order_sn: '', //订单编号
			express_no: '' //快递单号
		};
	},
	onLoad(options) {
		let { order_sn } = options;
		this.order_sn = order_sn;
		console.log(order_sn);
		this.getExpress();
	},
	methods: {
		/**
		 * @description 快递打开
		 */
		openPicker() {
			this.$refs.selector.show();
		},
		/**
		 * @description 供应商打开
		 */
		senderOpenPicker(){
			this.$refs.sender.show();
		},
		/**
		 * @description 快递选中确认数据
		 */
		onConfirm(val) {
			console.log(val);
			this.expressCompany = val.obj;
		},
		/**
		 * @description 供应商选中确认数据
		 */
		senderOnConfirm(val) {
			console.log(val);
			this.senderInfo = val.obj;
		},
		/**
		 * @description 获取快递公司列表
		 */
		getExpress() {
			this.$api
				.post(global.apiUrls.getExpressInfo,{
					
				})
				.then(res => {
					console.log(res);
					if (res.data.code == 1) {
						// if(!res.data.data.express_company || !res.data.data.sender_list){
						// 	this.$message.info('请去PC端设置快递与供应商');
						// 	setTimeout(()=>{
						// 		uni.navigateBack({
						// 			delta:1
						// 		})
						// 	},2000)
						// 	return;
						// }
						this.express_company = res.data.data.express_company;
						this.sender_list = res.data.data.sender_list;
					} else {
						this.$message.info(res.data.msg);
					}
				})
				.catch(err => {
					console.log(err);
				});
		},
		/**
		 * @description 扫码
		 */
		handleScan() {
			let that = this;
			uni.scanCode({
				success: function(res) {
					// console.log('条码类型：' + res.scanType);
					// console.log('条码内容：' + res.result);
					that.express_no = res.result;
				}
			});
		},
		/**
		 * @description 发货
		 */
		deliverGoods(){
			if(!this.expressCompany.aid){
				this.$message.info('请选择快递公司');
				return;
			}
			// if(!this.senderInfo.id){
			// 	this.$message.info('请选择供应商');
			// 	return;
			// }
			if(!this.express_no){
				this.$message.info('请输入或扫码录入快递单号');
				return;
			}
			let reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
			if(reg.test(this.express_no)) return this.$message.info('快递单号不能包含汉字');
			this.$api.post(global.apiUrls.shop_deliver_goods,
			{
				order_sn:this.order_sn,
				express_company_id:this.expressCompany.aid,
				// sender_company_id:this.senderInfo.id,
				express_no:this.express_no
			}
			).then(res=>{
				console.log(res);
				if(res.data.code == 1){
					this.$message.success('发货成功');
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},800)
				}else{
					this.$message.info(res.data.msg);
				}
			}).catch(err=>{
				console.log(err);
			})
		}
	}
};
</script>

<style scoped lang="scss">
.page {
	height: 100vh;
}
// 快递 start
.text-bf {
	color: #bfbfbf;
}
.express-wrap {
	padding: 0 32rpx;
	box-sizing: border-box;
	.express-item {
		height: 104rpx;
	}
}
// 快递 end
.express-btn-wrap {
	position: fixed;
	bottom: 64rpx;
	padding: 0 32rpx;
	width: 100%;
	box-sizing: border-box;
	.express-btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 45rpx;
		background: $bgtheme;
	}
}
</style>
